package com.woniu.dao;

import com.woniu.pojo.Menus;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface MenusMapper {
    int deleteByPrimaryKey(Integer menuId);

    int insert(Menus record);

    int insertSelective(Menus record);

    Menus selectByPrimaryKey(Integer menuId);

    int updateByPrimaryKeySelective(Menus record);

    int updateByPrimaryKey(Menus record);

    @Select("select perms from pc_menus m left join pc_roles_menus rm on m.menu_id = rm.menu_id left join " +
            "pc_roles r on rm.role_id = r.role_id where r.role_id = #{value}")
    List<String> findPermsByRoles(Integer roleId);

    @Select("select * from pc_menus m left join pc_roles_menus rm on m.menu_id = rm.menu_id " +
            "where rm.role_id = #{value}")
    List<Menus> selectMenusByRoles(Integer roleId);

    @Select("select * from pc_menus")
    List<Menus> selectAll();

    @Select("select * from pc_menus where title = #{value}")
    List<Menus> selectByTitle(String title);

    @Select("select * from pc_menus where parent_id = #{value}")
    Menus findByParentId(Integer mid);

    @Update("update pc_menus set sorting = #{sorting} where menu_id = #{menuId}")
    void updateSorting(@Param("menuId") Integer menuId, @Param("sorting") Integer sorting);

    @Select("select * from pc_menus where menu_id=#{value}")
    Menus findByMenuId(Integer menuId);

}